From de06b7597379df3edbcffc8fdff2acc8b1e35a73 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Sat, 4 Mar 2017 15:51:09 -0500 Subject: [PATCH] Restore the generated tests module created by `cargo new` Appears to have been removed unintentionally in #3004. --- src/cargo/ops/cargo_new.rs | 9 ++++++--- tests/new.rs | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 4905a1485..6f77801ff 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -582,7 +582,7 @@ fn collect_template_dir(template_path: &PathBuf, _: &Path) -> CargoResult Vec> { let lib_file = Box::new(InMemoryTemplateFile::new(PathBuf::from("src/lib.rs"), - String::from(r#"#[test] -fn it_works() { + String::from(r#"#[cfg(test)] +mod tests { + #[test] + fn it_works() { + } } "#))); vec![lib_file] diff --git a/tests/new.rs b/tests/new.rs index 2e9a770b0..1e666a7a3 100644 --- a/tests/new.rs +++ b/tests/new.rs @@ -32,6 +32,17 @@ fn simple_lib() { assert_that(&paths::root().join("foo/src/lib.rs"), existing_file()); assert_that(&paths::root().join("foo/.gitignore"), is_not(existing_file())); + let lib = paths::root().join("foo/src/lib.rs"); + let mut contents = String::new(); + File::open(&lib).unwrap().read_to_string(&mut contents).unwrap(); + assert_eq!(contents, r#"#[cfg(test)] +mod tests { + #[test] + fn it_works() { + } +} +"#); + assert_that(cargo_process("build").cwd(&paths::root().join("foo")), execs().with_status(0)); } -- 2.30.2